﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeBehind="MaterialLoanDetail.aspx.cs" Inherits="UdrinkWater_Project.Officer.MaterialLoanDetail" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <dx:ASPxRoundPanel ID="ASPxRoundPanel1" runat="server" 
        HeaderText="รายละเอียดการยืม-คืน" Width="100%">
        <PanelCollection>
            <dx:PanelContent runat="server" SupportsDisabledAttribute="True">
                <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" 
                    DataSourceID="SqlMaterialLoan" KeyFieldName="MaterialLoan_ID">
                    <Columns>
                        <dx:GridViewCommandColumn Caption="ทำรายการ" ShowInCustomizationForm="True" 
                            VisibleIndex="9">
                            <DeleteButton Text="ลบ" Visible="True">
                            </DeleteButton>
                            <CancelButton Text="ยกเลิก">
                            </CancelButton>
                            <ClearFilterButton Text="ยกเลิก" Visible="True">
                            </ClearFilterButton>
                        </dx:GridViewCommandColumn>
                        <dx:GridViewDataDateColumn Caption="วันที่ทำรายการ" FieldName="MaterialLoan_ID" 
                            ReadOnly="True" ShowInCustomizationForm="True" VisibleIndex="0">
                            <PropertiesDateEdit DisplayFormatString="dd/MM/yyyy HH:mm" 
                                EditFormat="DateTime">
                            </PropertiesDateEdit>
                        </dx:GridViewDataDateColumn>
                        <dx:GridViewDataTextColumn Caption="ชื่อ" FieldName="FirstName" 
                            ShowInCustomizationForm="True" VisibleIndex="1">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="นามสกุล" FieldName="LastName" 
                            ShowInCustomizationForm="True" VisibleIndex="2">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="ที่อยู่" FieldName="Address" 
                            ShowInCustomizationForm="True" VisibleIndex="3">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="อำเภอ" FieldName="AMPHUR_NAME" 
                            ShowInCustomizationForm="True" VisibleIndex="5">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="ตำบล" FieldName="DISTRICT_NAME" 
                            ShowInCustomizationForm="True" VisibleIndex="4">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="จังหวัด" FieldName="PROVINCE_NAME" 
                            ShowInCustomizationForm="True" VisibleIndex="6">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="สถานะ" FieldName="StatusLoan_Name" 
                            ShowInCustomizationForm="True" VisibleIndex="7">
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn Caption="พนักงานทำรายการ" FieldName="FullnameEmp" 
                            ReadOnly="True" ShowInCustomizationForm="True" VisibleIndex="8">
                        </dx:GridViewDataTextColumn>
                    </Columns>
                    <SettingsBehavior ConfirmDelete="True" />
                    <Settings ShowFilterRow="True" />
                    <SettingsText ConfirmDelete="ยืนยันการลบ" />
                    <SettingsDetail ShowDetailRow="True" />
                    <Templates>
                        <DetailRow>
                            <dx:ASPxGridView ID="ASPxGridView2" runat="server" AutoGenerateColumns="False" 
                                DataSourceID="SqlMaterialLoan_List" 
                                onbeforeperformdataselect="ASPxGridView2_BeforePerformDataSelect" Width="100%">
                                <TotalSummary>
                                    <dx:ASPxSummaryItem DisplayFormat="รวม {0:#,###.00}" FieldName="TotalPrice" 
                                        ShowInColumn="รวม" ShowInGroupFooterColumn="รวม" SummaryType="Sum" />
                                </TotalSummary>
                                <Columns>
                                    <dx:GridViewDataDateColumn FieldName="MaterialLoan_ID" Visible="False" 
                                        VisibleIndex="0">
                                    </dx:GridViewDataDateColumn>
                                    <dx:GridViewDataTextColumn Caption="รหัสสินค้า" FieldName="Product_ID" 
                                        VisibleIndex="1">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn Caption="ชื่อสินค้า" FieldName="Product_name" 
                                        VisibleIndex="2">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn Caption="จำนวน" FieldName="Count" VisibleIndex="3">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn Caption="หน่วย" FieldName="Unit_Name" 
                                        VisibleIndex="4">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn Caption="ราคาต่อหน่วย" FieldName="Price" 
                                        VisibleIndex="5">
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataTextColumn Caption="รวม" FieldName="TotalPrice" ReadOnly="True" 
                                        VisibleIndex="6">
                                    </dx:GridViewDataTextColumn>
                                </Columns>
                                <Settings ShowFooter="True" />
                            </dx:ASPxGridView>
                            <asp:SqlDataSource ID="SqlMaterialLoan_List" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                                SelectCommand="SELECT TB_MaterialLoan_List.MaterialLoan_ID, TB_MaterialLoan_List.Product_ID, TB_Product.Product_name, TB_MaterialLoan_List.Count, TB_Unit_Category.Unit_Name, TB_MaterialLoan_List.Price, TB_MaterialLoan_List.Price * TB_MaterialLoan_List.Count AS TotalPrice FROM TB_MaterialLoan_List INNER JOIN TB_Product ON TB_MaterialLoan_List.Product_ID = TB_Product.Product_ID INNER JOIN TB_Unit_Category ON TB_Product.Unit = TB_Unit_Category.Unit_ID WHERE (TB_MaterialLoan_List.MaterialLoan_ID = @MaterialLoan_ID)">
                                <SelectParameters>
                                    <asp:SessionParameter Name="MaterialLoan_ID" SessionField="MaterialLoan_ID" />
                                </SelectParameters>
                            </asp:SqlDataSource>
                        </DetailRow>
                    </Templates>
                </dx:ASPxGridView>
                <asp:SqlDataSource ID="SqlMaterialLoan" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                    SelectCommand="SELECT TB_MaterialLoan.MaterialLoan_ID, TB_MaterialLoan.FirstName, TB_MaterialLoan.LastName, TB_MaterialLoan.Address, TB_Aumphur.AMPHUR_NAME, TB_District.DISTRICT_NAME, TB_Province.PROVINCE_NAME, TB_StatusLoan.StatusLoan_Name, TB_Employee.Firstname + '  ' + TB_Employee.Lastname AS FullnameEmp FROM TB_MaterialLoan INNER JOIN TB_Aumphur ON TB_MaterialLoan.Aumphur_ID = TB_Aumphur.AMPHUR_ID INNER JOIN TB_District ON TB_MaterialLoan.District_ID = TB_District.DISTRICT_ID INNER JOIN TB_Province ON TB_MaterialLoan.Province_ID = TB_Province.PROVINCE_ID INNER JOIN TB_StatusLoan ON TB_MaterialLoan.Status = TB_StatusLoan.StatusLoan_ID INNER JOIN TB_Employee ON TB_MaterialLoan.Employee_ID = TB_Employee.ID_Card ORDER BY TB_MaterialLoan.MaterialLoan_ID DESC">
                </asp:SqlDataSource>
            </dx:PanelContent>
        </PanelCollection>
    </dx:ASPxRoundPanel>
</asp:Content>
